home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / pdftops / xpdf / h / Stream-CCI < prev    next >
Text File  |  1996-05-23  |  7KB  |  395 lines

  1. //========================================================================
  2. //
  3. // Stream-CCITT.h
  4. //
  5. // Tables for CCITT Fax decoding.
  6. //
  7. // Copyright 1996 Derek B. Noonburg
  8. //
  9. //========================================================================
  10.  
  11. struct CCITTCode {
  12.   short code;
  13.   short n;
  14. };
  15.  
  16. struct CCITTCodeTable {
  17.   short numCodes;
  18.   CCITTCode *codes;
  19. };
  20.  
  21. #define ccittMaxCodeLen 13
  22.  
  23. #define ccittEOL -2
  24.  
  25. //------------------------------------------------------------------------
  26. // 2D codes
  27. //------------------------------------------------------------------------
  28.  
  29. #define twoDimPass   0
  30. #define twoDimHoriz  1
  31. #define twoDimVert0  2
  32. #define twoDimVertR1 3
  33. #define twoDimVertL1 4
  34. #define twoDimVertR2 5
  35. #define twoDimVertL2 6
  36. #define twoDimVertR3 7
  37. #define twoDimVertL3 8
  38.  
  39. static CCITTCode twoDim1Table[1] = {
  40.   {0x0001, twoDimVert0}
  41. };
  42.  
  43. static CCITTCode twoDim3Table[3] = {
  44.   {0x0001, twoDimHoriz},
  45.   {0x0002, twoDimVertL1},
  46.   {0x0003, twoDimVertR1}
  47. };
  48.  
  49. static CCITTCode twoDim4Table[1] = {
  50.   {0x0001, twoDimPass}
  51. };
  52.  
  53. static CCITTCode twoDim6Table[2] = {
  54.   {0x0002, twoDimVertL2},
  55.   {0x0003, twoDimVertR2}
  56. };
  57.  
  58. static CCITTCode twoDim7Table[2] = {
  59.   {0x0002, twoDimVertL3},
  60.   {0x0003, twoDimVertR3}
  61. };
  62.  
  63. static CCITTCode twoDim12Table[1] = {
  64.   {0x0001, ccittEOL}
  65. };
  66.  
  67. static CCITTCodeTable twoDimTable[ccittMaxCodeLen + 1] = {
  68.   {0, NULL},
  69.   {1, twoDim1Table},
  70.   {0, NULL},
  71.   {3, twoDim3Table},
  72.   {1, twoDim4Table},
  73.   {0, NULL},
  74.   {2, twoDim6Table},
  75.   {2, twoDim7Table},
  76.   {0, NULL},
  77.   {0, NULL},
  78.   {0, NULL},
  79.   {0, NULL},
  80.   {1, twoDim12Table},
  81.   {0, NULL}
  82. };
  83.  
  84. //------------------------------------------------------------------------
  85. // white run lengths
  86. //------------------------------------------------------------------------
  87.  
  88. static CCITTCode white4Table[6] = {
  89.   {0x0007, 2},
  90.   {0x0008, 3},
  91.   {0x000b, 4},
  92.   {0x000c, 5},
  93.   {0x000e, 6},
  94.   {0x000f, 7}
  95. };
  96.  
  97. static CCITTCode white5Table[6] = {
  98.   {0x0007, 10},
  99.   {0x0008, 11},
  100.   {0x0012, 128},
  101.   {0x0013, 8},
  102.   {0x0014, 9},
  103.   {0x001b, 64}
  104. };
  105.  
  106. static CCITTCode white6Table[9] = {
  107.   {0x0003, 13},
  108.   {0x0007, 1},
  109.   {0x0008, 12},
  110.   {0x0017, 192},
  111.   {0x0018, 1664},
  112.   {0x002a, 16},
  113.   {0x002b, 17},
  114.   {0x0034, 14},
  115.   {0x0035, 15}
  116. };
  117.  
  118. static CCITTCode white7Table[12] = {
  119.   {0x0003, 22},
  120.   {0x0004, 23},
  121.   {0x0008, 20},
  122.   {0x000c, 19},
  123.   {0x0013, 26},
  124.   {0x0017, 21},
  125.   {0x0018, 28},
  126.   {0x0024, 27},
  127.   {0x0027, 18},
  128.   {0x0028, 24},
  129.   {0x002b, 25},
  130.   {0x0037, 256}
  131. };
  132.  
  133. static CCITTCode white8Table[42] = {
  134.   {0x0002, 29},
  135.   {0x0003, 30},
  136.   {0x0004, 45},
  137.   {0x0005, 46},
  138.   {0x000a, 47},
  139.   {0x000b, 48},
  140.   {0x0012, 33},
  141.   {0x0013, 34},
  142.   {0x0014, 35},
  143.   {0x0015, 36},
  144.   {0x0016, 37},
  145.   {0x0017, 38},
  146.   {0x001a, 31},
  147.   {0x001b, 32},
  148.   {0x0024, 53},
  149.   {0x0025, 54},
  150.   {0x0028, 39},
  151.   {0x0029, 40},
  152.   {0x002a, 41},
  153.   {0x002b, 42},
  154.   {0x002c, 43},
  155.   {0x002d, 44},
  156.   {0x0032, 61},
  157.   {0x0033, 62},
  158.   {0x0034, 63},
  159.   {0x0035, 0},
  160.   {0x0036, 320},
  161.   {0x0037, 384},
  162.   {0x004a, 59},
  163.   {0x004b, 60},
  164.   {0x0052, 49},
  165.   {0x0053, 50},
  166.   {0x0054, 51},
  167.   {0x0055, 52},
  168.   {0x0058, 55},
  169.   {0x0059, 56},
  170.   {0x005a, 57},
  171.   {0x005b, 58},
  172.   {0x0064, 448},
  173.   {0x0065, 512},
  174.   {0x0067, 640},
  175.   {0x0068, 576}
  176. };
  177.  
  178. static CCITTCode white9Table[16] = {
  179.   {0x0098, 1472},
  180.   {0x0099, 1536},
  181.   {0x009a, 1600},
  182.   {0x009b, 1728},
  183.   {0x00cc, 704},
  184.   {0x00cd, 768},
  185.   {0x00d2, 832},
  186.   {0x00d3, 896},
  187.   {0x00d4, 960},
  188.   {0x00d5, 1024},
  189.   {0x00d6, 1088},
  190.   {0x00d7, 1152},
  191.   {0x00d8, 1216},
  192.   {0x00d9, 1280},
  193.   {0x00da, 1344},
  194.   {0x00db, 1408}
  195. };
  196.  
  197. static CCITTCode white11Table[3] = {
  198.   {0x0008, 1792},
  199.   {0x000c, 1856},
  200.   {0x000d, 1920},
  201. };
  202.  
  203. static CCITTCode white12Table[11] = {
  204.   {0x0001, ccittEOL},
  205.   {0x0012, 1984},
  206.   {0x0013, 2048},
  207.   {0x0014, 2112},
  208.   {0x0015, 2176},
  209.   {0x0016, 2240},
  210.   {0x0017, 2304},
  211.   {0x001c, 2368},
  212.   {0x001d, 2432},
  213.   {0x001e, 2496},
  214.   {0x001f, 2560}
  215. };
  216.  
  217. static CCITTCodeTable whiteTable[ccittMaxCodeLen + 1] = {
  218.   {0, NULL},
  219.   {0, NULL},
  220.   {0, NULL},
  221.   {0, NULL},
  222.   {6, white4Table},
  223.   {6, white5Table},
  224.   {9, white6Table},
  225.   {12, white7Table},
  226.   {42, white8Table},
  227.   {16, white9Table},
  228.   {0, NULL},
  229.   {3, white11Table},
  230.   {11, white12Table},
  231.   {0, NULL}
  232. };
  233.  
  234. //------------------------------------------------------------------------
  235. // black run lengths
  236. //------------------------------------------------------------------------
  237.  
  238. static CCITTCode black2Table[2] = {
  239.   {0x0002, 3},
  240.   {0x0003, 2}
  241. };
  242.  
  243. static CCITTCode black3Table[2] = {
  244.   {0x0002, 1},
  245.   {0x0003, 4}
  246. };
  247.  
  248. static CCITTCode black4Table[2] = {
  249.   {0x0002, 6},
  250.   {0x0003, 5}
  251. };
  252.  
  253. static CCITTCode black5Table[1] = {
  254.   {0x0003, 7}
  255. };
  256.  
  257. static CCITTCode black6Table[2] = {
  258.   {0x0004, 9},
  259.   {0x0005, 8}
  260. };
  261.  
  262. static CCITTCode black7Table[3] = {
  263.   {0x0004, 10},
  264.   {0x0005, 11},
  265.   {0x0007, 12}
  266. };
  267.  
  268. static CCITTCode black8Table[2] = {
  269.   {0x0004, 13},
  270.   {0x0007, 14}
  271. };
  272.  
  273. static CCITTCode black9Table[1] = {
  274.   {0x0018, 15}
  275. };
  276.  
  277. static CCITTCode black10Table[5] = {
  278.   {0x0008, 18},
  279.   {0x000f, 64},
  280.   {0x0017, 16},
  281.   {0x0018, 17},
  282.   {0x0037, 0}
  283. };
  284.  
  285. static CCITTCode black11Table[10] = {
  286.   {0x0008, 1792},
  287.   {0x000c, 1856},
  288.   {0x000d, 1920},
  289.   {0x0017, 24},
  290.   {0x0018, 25},
  291.   {0x0028, 23},
  292.   {0x0037, 22},
  293.   {0x0067, 19},
  294.   {0x0068, 20},
  295.   {0x006c, 21}
  296. };
  297.  
  298. static CCITTCode black12Table[55] = {
  299.   {0x0001, ccittEOL},
  300.   {0x0012, 1984},
  301.   {0x0013, 2048},
  302.   {0x0014, 2112},
  303.   {0x0015, 2176},
  304.   {0x0016, 2240},
  305.   {0x0017, 2304},
  306.   {0x001c, 2368},
  307.   {0x001d, 2432},
  308.   {0x001e, 2496},
  309.   {0x001f, 2560},
  310.   {0x0024, 52},
  311.   {0x0027, 55},
  312.   {0x0028, 56},
  313.   {0x002b, 59},
  314.   {0x002c, 60},
  315.   {0x0033, 320},
  316.   {0x0034, 384},
  317.   {0x0035, 448},
  318.   {0x0037, 53},
  319.   {0x0038, 54},
  320.   {0x0052, 50},
  321.   {0x0053, 51},
  322.   {0x0054, 44},
  323.   {0x0055, 45},
  324.   {0x0056, 46},
  325.   {0x0057, 47},
  326.   {0x0058, 57},
  327.   {0x0059, 58},
  328.   {0x005a, 61},
  329.   {0x005b, 256},
  330.   {0x0064, 48},
  331.   {0x0065, 49},
  332.   {0x0066, 62},
  333.   {0x0067, 63},
  334.   {0x0068, 30},
  335.   {0x0069, 31},
  336.   {0x006a, 32},
  337.   {0x006b, 33},
  338.   {0x006c, 40},
  339.   {0x006d, 41},
  340.   {0x00c8, 128},
  341.   {0x00c9, 192},
  342.   {0x00ca, 26},
  343.   {0x00cb, 27},
  344.   {0x00cc, 28},
  345.   {0x00cd, 29},
  346.   {0x00d2, 34},
  347.   {0x00d3, 35},
  348.   {0x00d4, 36},
  349.   {0x00d5, 37},
  350.   {0x00d6, 38},
  351.   {0x00d7, 39},
  352.   {0x00da, 42},
  353.   {0x00db, 43}
  354. };
  355.  
  356. static CCITTCode black13Table[20] = {
  357.   {0x004a, 640},
  358.   {0x004b, 704},
  359.   {0x004c, 768},
  360.   {0x004d, 832},
  361.   {0x0052, 1280},
  362.   {0x0053, 1344},
  363.   {0x0054, 1408},
  364.   {0x0055, 1472},
  365.   {0x005a, 1536},
  366.   {0x005b, 1600},
  367.   {0x0064, 1664},
  368.   {0x0065, 1728},
  369.   {0x006c, 512},
  370.   {0x006d, 576},
  371.   {0x0072, 896},
  372.   {0x0073, 960},
  373.   {0x0074, 1024},
  374.   {0x0075, 1088},
  375.   {0x0076, 1152},
  376.   {0x0077, 1216}
  377. };
  378.  
  379. static CCITTCodeTable blackTable[ccittMaxCodeLen + 1] = {
  380.   {0, NULL},
  381.   {0, NULL},
  382.   {2, black2Table},
  383.   {2, black3Table},
  384.   {2, black4Table},
  385.   {1, black5Table},
  386.   {2, black6Table},
  387.   {3, black7Table},
  388.   {2, black8Table},
  389.   {1, black9Table},
  390.   {5, black10Table},
  391.   {10, black11Table},
  392.   {55, black12Table},
  393.   {20, black13Table}
  394. };
  395.